package com.gridmobi.xrtb.model.rtb;


/**
 *
 */

public class AdAjaxTemplate {
    private static String jsAD = "<!DOCTYPE html>\n" +
            "<html>\n" +
            "<head>\n" +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" +
            "    <meta http-equiv=\"Pragma\" content=\"no-cache\">\n" +
            "    <meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n" +
            "    <meta http-equiv=\"Expires\" content=\"0\">\n" +
            "    <meta content=\"always\" name=\"referrer\">\n" +
            "    <title></title>\n" +
            "    <script type=\"text/javascript\">\n" +
            "        var Ajax = {\n" +
            "            get: function (url, fn) {\n" +
            "                var xhr = new XMLHttpRequest();\n" +
            "                xhr.open('GET', url, true);\n" +
            "                xhr.onreadystatechange = function () {\n" +
            "                    if (xhr.status == 200 ) {\n" +
            "                        fn.call(this, xhr.responseText);\n" +
            "                    }\n" +
            "                };\n" +
            "                xhr.send();\n" +
            "            }\n" +
            "        }\n" +
            "        function funtz() {\n" +
            "            Ajax.get('__TRACKURL__', (f, res) => {\n" +
            "                Ajax.get('__LANDURL__', () => {\n" +
            "                });\n" +
            "            })\n" +
            "            location.href='__STOREURL__';\n" +
            "        }\n" +
            "        setTimeout(funtz, 1);\n" +
            "    </script>\n" +
            "    <noscript>\n" +
            "        <meta http-equiv=\"refresh\" content=\"0\">\n" +
            "    </noscript>\n" +
            "</head>\n" +
            "<body></body>\n" +
            "</html>";

    public static String jsAd(String rtbLandUrl,String  trackurl,String appstoreurl) {
        String js = jsAD.replaceAll("__LANDURL__", rtbLandUrl).replaceAll("__TRACKURL__", trackurl).replaceAll("__STOREURL__", appstoreurl);
        return js;
    }

}

